using Rosetta.Runtime;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Main : MonoBehaviour
{
    public static Main Self;

    // Start is called before the first frame update
    public Dropdown Lang;

    public List<LangFlag> Langs;

    public GameObject TitleView;

    public GameObject MenuView;

    public GameObject MainView;

    [HideInInspector]
    public GameObject View;

    public Database DB;

    private Stack<GameObject> _viewStack = new Stack<GameObject>();

    private void Awake()
    {
        Self = this;
        Rosetta.Runtime.Rosetta.Init();
        Lang.options.Clear();
        Langs.ForEach(flag => Lang.options.Add(new Dropdown.OptionData(Rosetta.Runtime.Rosetta.LangNames[flag])));
        Lang.value = Langs.IndexOf(Rosetta.Runtime.Rosetta.Locale);
    }

    private void Start()
    {
        GotoView(TitleView);
    }

    public void StartGame()
    {
        GotoView(MainView);
    }

    public void ExitGame()
    {
        Application.Quit();
    }

    public void Exit()
    {
        GotoView(TitleView);
    }

    public void GotoView(GameObject view)
    {
        if (View != null) View.SetActive(false);
        View = view;
        View.SetActive(true);
    }

    public void PushView(GameObject view)
    {
        _viewStack.Push(View);
        GotoView(view);
    }

    public void PopView()
    {
        GotoView(_viewStack.Pop());
    }

    public void ShowMenu()
    {
        PushView(MenuView);
    }

    public void ChangeLang(int id)
    {
        Rosetta.Runtime.Rosetta.Locale = Langs[id];
    }
}